home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / probeclocks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-06  |  6.0 KB  |  207 lines

  1. /*  SVGATextMode -- An SVGA textmode manipulation/enhancement tool
  2.  *
  3.  *  Copyright (C) 1995,1996  Koen Gadeyne
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. /* THIS PROGRAM IS UNDER CONSTRUCTION --- NOT FUNCTIONAL YET */
  21.  
  22. /***
  23.  *** probe_clocks: A standalone replacement for the XFREE86 "X -probeonly" command.
  24.  ***               Probes all available pixel clocks using the mechanism specified
  25.  ***               In the /etc/ClockConfig or the /etc/TextConfig file.
  26.  ***               This doesn't need XFree86 to be installed.
  27.  ***
  28.  ***               Since the whole STM package has no chipset detection code in it,
  29.  ***               you have to define the chipset AND the clocks in the config file.
  30.  ***               The clock VALUES may be wrong, but the probe will only probe for
  31.  ***               those that are mentionned in the config file.
  32.  ***
  33.  ***               This is not very nice. We need to use the XFree86 "save" functions
  34.  ***               to save register contents before we go on, and then restore them
  35.  ***               afterwards.
  36.  ***/
  37.  
  38. #include "misc.h"
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <unistd.h>
  44. #include <math.h>
  45.  
  46. #include "vga_prg.h"
  47. #include "setclock.h"
  48. #include "validate.h"
  49. #include "messages.h"
  50.  
  51. char *CommandName;
  52. char ConfigFile[1024]=CLOCK_CONF_FILE;
  53. bool debug_messages=FALSE;
  54.  
  55. void usage()
  56. {
  57.      PMESSAGE(("version %s. (c) 1995,1996 Koen Gadeyne.\n Usage: %s [options]\n\n\
  58.      Options: -n  Don't program VGA hardware (rather useless)\n\
  59.               -d  print debugging information\n\
  60.               -h  print usage information\n\
  61.               -f  fast mode: probe only one clock `precisely', and the rest faster
  62.                   and less accurate (XFree86 method for all but the first probe)
  63.               -t <ConfigFile>  Use alternative config file instead of the default\n\
  64.                  (= %s if that exists, or %s otherwise)\n\n",
  65.      VERSION, CommandName, CLOCK_CONF_FILE, CONFIGFILE));
  66. }
  67.  
  68. void Xfree_probe_clocks()
  69. /* this is largely the code from the XFree86 file XFree86-3.1.1-1/xc/programs/Xserver/hw/xfree86/common_hw/xf86_ClkPr.c */
  70. {
  71. }
  72.  
  73. /****************************************************************************************************************************/
  74.  
  75. int main (int argc, char* argv[])
  76. {
  77.   bool program_hardware=TRUE;
  78.   bool fast_mode=FALSE;
  79.   int chipset=CS_NONE;
  80.   const char *str_chipsets[NUM_CHIPSETS] = CHIPSET_STRINGS;
  81.   FILE *param_file;
  82.   int optionmask;
  83.   int n;
  84.   t_clockdef ck;
  85.   char c;
  86.   modestruct m, probe_m;
  87.   char tempstr[1024]="";
  88.     
  89.  /*
  90.   * check if default config file exists. If not, use TextConfig.
  91.   */
  92.   
  93.   if ((param_file=fopen(ConfigFile,"r"))==NULL) strcpy(ConfigFile, CONFIGFILE);
  94.   else fclose(param_file);
  95.  
  96.  /*
  97.   * command-line argument parsing
  98.   */
  99.  
  100.   CommandName = argv[0];
  101.  
  102.   while ((c = getopt (argc, argv, "ndfht:")) != EOF)
  103.     switch (c)
  104.     {
  105.       case 'n': program_hardware=FALSE;
  106.                 break;
  107.       case 'd': debug_messages=TRUE;
  108.                 break;
  109.       case 'f': fast_mode=TRUE;
  110.                 break;
  111.       case 'h': usage();
  112.                 exit(0);
  113.                 break;
  114.       case 't': strcpy(ConfigFile, optarg);
  115.                 break;
  116.       case '?': usage();
  117.                 PERROR(("Bad option '-%c'\n",(char)optopt));
  118.                 exit(-1);
  119.                 break;
  120.       default: PERROR(("getopt returned unknown token '%c'.\n",c));
  121.     }
  122.    
  123.   PVERSION;
  124.  
  125.   if (argc>optind+1)
  126.   {
  127.     usage();
  128.     PERROR(("Too many parameters on command line.\n"));
  129.   }
  130.  
  131.  /*
  132.   * open parameter file
  133.   */
  134.   param_file = open_param_file(ConfigFile);
  135.  
  136.  
  137.  /*
  138.   * get chipset definition
  139.   */
  140.   sscanf(findlabel(param_file, "ChipSet", LABEL_REQUIRED+LABEL_FROMSTART), "%*s %s", tempstr);
  141.   chipset = findoption(tempstr, str_chipsets, NUM_CHIPSETS, "chip set");
  142.  
  143.  
  144.  /*
  145.   * Option parsing. Not all chips support all options
  146.   */
  147.  
  148.   optionmask = parse_opt(param_file, chipset, str_chipsets[chipset]);
  149.  
  150.  /*
  151.   * parse clock configuration in config file, fill structure with info
  152.   */
  153.  
  154.   parse_clock(param_file, chipset, &ck);
  155.   if (ck.type & CK_CLOCKCHIP)
  156.   {
  157.     PWARNING(("\n\tThe config file defines a ClockChip on this system.\n"\
  158.               "\tA ClockChip is supposed to be able to create ANY clock.\n"\
  159.               "\tClock probing is a bit useless then.\n"));
  160.   }
  161.   
  162.  /*
  163.   * Close the config file. We don't need it anymore.
  164.   */
  165.  
  166.   fclose(param_file);
  167.   
  168.  /*
  169.   * finally do it... maybe
  170.   */
  171.   
  172.   if (program_hardware)
  173.   {
  174.     get_VGA_io_perm(chipset);
  175.  
  176.     /* sync disks if requested. Is there any way to do this and be SURE _all_ data has been flushed? */
  177.     if (optionmask & OPT_SYNC)
  178.     {
  179.       PDEBUG(("Syncing disks...\n"));
  180.       sync(); sleep(2); /* same as in "reboot" command. Hopefully enough */
  181.     }
  182.  
  183.     unlock(chipset);
  184.  
  185.     getmode(&m, TRUE); /* get the current pixel clock so we can restore it */
  186.     
  187.     PDEBUG(("pixel clock before tests = %1.2f\n", m.pclock));
  188.     for (n=0; n<ck.num_clocks; n++)
  189.     {
  190.       if (ck.clocks[n]==CKVAL_PROGRAMMABLE)
  191.         PMESSAGE(("pixel clock %d is programmable\n", n));
  192.       else
  193.       {
  194.         do_clock(chipset, &ck, ck.clocks[n], n, optionmask);
  195.         getmode(&probe_m, TRUE);
  196.         PMESSAGE(("pixel clock %d = %1.2f\n", n, probe_m.pclock));
  197.       }
  198.     }
  199.  
  200.    PDEBUG(("restoring old pixel clock\n"));
  201.    do_clock(chipset, &ck, m.pclock, 0, optionmask);  /* restore old clock */
  202.       
  203.   }
  204.   return(0);
  205. }
  206.  
  207.